PHP Socket network operation class definition and usage example, socket example
This example describes the definition and usage of PHP Socket network operations. We will share this with you for your reference. The details are as follows:
Web Front-end testing:
Mysocket. php
socket continues to be in the listening state, it continues to receive connection requests from other client sockets.2. Socket connection and TCP connectionWhen you create a socket connection, you can specify the transport layer protocol used, which can support different transport layer protocols (TCP or UDP), which is a TCP connection when a connection is made
Definition of sockets usage scenarios:
(a) Socket usage scenario:
For example: The browser process communicates with the Web server process;
such as: QQ process and friends QQ process communication;
(ii) Local process communication process communication on the network:
(1) Local process communication:
The local interprocess communication (IPC) is available in a number of ways, but can be summarize
There are two types of computer data storage priorities: high byte priority and low byte priority. Data on the internet is transmitted over the network in high byte precedence. Therefore, for machines that store data in low byte precedence mode, data transmission over the Internet requires conversion.
The first structure type we will discuss is struct sockaddr, which is used to save socket information:Struct sockaddr {Unsigned short sa_family;/* addr
Sock function Introduction
Name of function
Describe
Socket_accept ()
Accept a socket connection
Socket_bind ()
Bind the socket to an IP address and port
Socket_clear_error ()
Clears the socket error or the last error code
Socket_close ()
Close a socke
and write write/read–> close" mode. My understanding is that the socket is an implementation of the pattern, the socket is a special kind of file, some of the socket function is the operation of it (read/write Io, open, close), these functions we introduced later.
The origin of the word socket
The first use
client socket request, passively opens, and begins receiving client requests until the client returns the connection information. When the socket enters the blocking state, the so-called blocking is the Accept () method until the client returns the connection information, and begins receiving the next client understanding request7, the client connection is successful, send the connection status information
Socket (socket)
First look at the definition:
typedef unsigned int u_int;
typedef u_int SOCKET;
Socket is equivalent to the network communication at both ends of the socket, as long as the other side of the
One, socketSockets are objects that provide the current portability standard for a network application provider on a specific network protocol (such as TCP/IP,ICMP/IP,UDP/IP, etc.). They allow programs to accept and connect, such as sending and receiving data. In order to establish a communication channel, it is extremely important for each endpoint of a network communication to have a socket object.Sockets are part of the core of BSD Unix systems, an
only be used within a function are called "local variables".Note: The var keyword is omitted anywhere, and the variables defined are "global variables" (which can be used outside of the function) so, in general, do not omit the var keyword.Assignment Value and assignment address:Assignment value: Used to assign a basic data type (only one value) to a variable.Reference address: Used to assign a composite data type (possibly with multiple values) to a variable. All two variables change at the sa
ntohl (uint32_t netlong); uint16_t ntohs (uint16_t netshort);/** Note: h stands for (local) host; n stands for network; s stands for short; l stands for long ;*/
// Test the Conversion Result: int main () {int localeData = 0x12345678; char * p = (char *) localeData; printf ("Begin: % 0x % 0x % 0x % 0x \ n ", p [0], p [1], p [2], p [3]); // convert local bytes to network bytes int inetData = htonl (localeData); p = (char *) inetData; printf ("After: % 0x % 0x % 0x % 0x \ n ", p [0], p [1], p [
Java socket packet communication (I) socket establishment, socket Packet
Java socket packet communication (I) socket Establishment
Today, I will share with you how to use socket for communication in java. Let's take a look at TCP/
in_addr the network address stored in the struct to a number. number. The format of numbers.L Inet_ntoa () uses struct in_addr as a parameter, not a long integer value.4. Basic Socket Invocationsocket () functionGet socket descriptor The definition of the socket function is as follows:#include#includeint
Assuming that the TCP socket server is already established and listening to the client's connection, the client can initiate the connection through the socket class. After the client initiates a connection request, it passively waits for a response from the server. This class is also located in the java.net package, which contains many methods for establishing connections, manipulating data flows, and so on
SD. The prototype is as follows:
Socket wsasocket (int af, int type, int protocol, lpwsaprotocol_infoLpprotocolinfo, group G, DWORD dwflags );
The parameters are defined:AF: The address family, which is generally af_inet and refers to the IPv4 (the Internet Protocol version 4) address family.Type: socket type. If you create the original socket, us
Socket-series socket server-how to communicate with the client, socket serverThe above sections have introduced the working steps of ServerSocket and Socket respectively, and analyzed their operating principles from the application layer to the bottom layer of the system. We have understood their respective parts. Now
Socket series What is socket and socket Series1. What is socket?Socket is the intermediate abstraction layer for communications between the application layer and the TCP/IP protocol family. It is a group of interfaces that the application layer can send and receive data by c
SocketI. OverviewSockets are also commonly referred to as "sockets," which describe IP addresses and ports, and are a handle to a chain of communication, where applications usually make requests to the network through "sockets" or respond to network requests.Sockets originate from UNIX, and one of the basic philosophies of unix/linux is "Everything is file", and the file is operated with "open" "Read and Write" "Off" mode. Socket is an implementation
BYTE order:
Host byte order: Different hosts have different byte order, x86: Small end, network byte order (network byte order): big-endian byte sequence;
0. What is a socketSockets are communications between network processes (network interprocess communication, also known as network IPC) interfaces that enable the process to communicate with other processes, whether on the same computer or not, as an abstraction of the communication endpoint, like a file descriptor Descriptor) is an abstract r
Introduction Java NiO, introduced from JDK1.4, provides a completely different way of working with standard IO. The NIO package (java.nio.*) introduces four key abstract data types that work together to address some of the problems in traditional I/O classes. 1, Buffer: It is a linear table structure that contains data and is used for reading and writing. It also provides a special class for I/O operations for memory-mapped files. 2, Charset: It provides the operation of a Unicode string
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.